//*- coding = utf-8 -*-
//@Time : 2022-11-12 16:12
//@Author : 管茂良
//@File : config.js
//@web  : www.php-china.com
//@Software: WebStorm
import {DocumentBuilder, SwaggerModule} from '@nestjs/swagger';
//系统基础设置
export const sysBase = {
  host:"http://127.0.0.1",
  port:3000
}

//jwt配置
export const jwtKey = {
  secret: 'vueCms_xg',
  expireTime:"10h"
};
//跨域配置
export const corsConfig = {
  origin: '*',
  optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204
}

//mysql配置
export const handleMyConfig = ()=>{
  let mysqlConfig:any = {
    type: 'mysql',//数据库类型
    host: '127.0.0.1',//ip
    port: 3306,//端口号
    username: 'root',//账号
    password: 'admin123',//密码
    database: 'g_vuecms_xg',//数据库名
    synchronize: true,//是否自动将实体类同步到数据库
    retryDelay:500,//重试连接数据库间隙
    retryAttempts:10,//重试连接数据库的次数
    // entities: [__dirname+"/**/*.entity{.ts,.js}"],//实体文件
    autoLoadEntities:true,//如果为true，将自动加载实体 forFeature()方法注册的每个实体都将自动添加到配置对象的实体
    cache:false,//要启用缓存
    logging:true,//开启日志
  }
  return mysqlConfig;
}

//redis配置
export const redisConfig = {
  port: 6379,
  host: '119.45.115.191',
  password: '12Q4qqeEzxdY11',
  db: 0
}
export const uploadImgConfig = {
  imgBaseUrl:"./public/uploads/img",//图片上传路径
  artContentImgBaseUrl:"./public/uploads/artContentImg",//文章图片上传路径
}

//状态监控配置
export const statusMonitorConfig = {
  pageTitle: '',
  // 配置端口
  port: 3000,
  path: '/statusMonitor',
  ignoreStartsWith: '/health/alive',
  spans: [
    {
      interval: 1, // Every second
      retention: 60, // Keep 60 datapoints in memory
    },
    {
      interval: 5, // Every 5 seconds
      retention: 60,
    },
    {
      interval: 15, // Every 15 seconds
      retention: 60,
    },
  ],
  chartVisibility: {
    cpu: true,
    mem: true,
    load: true,
    responseTime: true,
    rps: true,
    statusCodes: true,
  },
  healthChecks: [],
};

//swagger配置函数
export const handleBuildSwagger = (app)=>{
  const config = new DocumentBuilder()
    .addBearerAuth()
    .setTitle('vueCms')
    .setDescription('沉默小管')
    .setVersion('1.0')
    .addTag('vue')
    .build();
  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('sysApi', app, document,{
    // 自定义样式
    customCssUrl: '/css/swagger/theme-muted.css',
  });
}


